#include<bits/stdc++.h>
using namespace std;

struct node {
	int w, s;
} a[50005];

//bool cmp(node x, node y) {
//	return x.w - y.s > y.w - x.s;
//}

bool cmp(node x, node y) {
	return x.s > y.s;
}

int fun(int n) {

	sort(a, a + n, cmp);

	int pre = a[0].w, ans = -a[0].s;
	for (int i = 1; i < n; i++) {
		ans = max(ans, pre - a[i].s);
		pre += a[i].w;
	}
	return ans;
}

signed main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i].w >> a[i].s;
	cout << fun(n);
	return 0;
}
